//
//  SkinVC.m
//  TheProjectName
//
//  Created by 李劲成 on 16/5/26.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "SkinVC.h"
#import "SkinCell.h"
@interface SkinVC ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *m_collerction;

@property (nonatomic, strong) NSMutableArray *m_dataSource;

@end

@implementation SkinVC

- (void)viewDidLoad {
    [super viewDidLoad];

    [self handleData];
    [self createSubViews];
    
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self config];
}
- (void)config{
    self.navigationItem.title = @"一键换肤";
     self.navigationItem.leftBarButtonItem = BARBUTTONIMAGE(@"aligh_left_27.291428571429px_1189116_easyicon.net", self, @selector(presentLeftMenuViewController:));
}
- (void)handleData{
    self.m_dataSource = [NSMutableArray array];
    for (int i = 1; i < 11; i++) {
      UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
        [_m_dataSource addObject:image];
    }
   
}

- (void)createSubViews{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.itemSize = CGSizeMake((SCREEN_WIDTH  - 40) / 2.f, (SCREEN_HEIGHT - 114) / 3.f);
    self.m_collerction =[[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    _m_collerction.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_m_collerction];
    [_m_collerction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(5);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-5);
        make.left.equalTo(self.view.mas_left).with.offset(5);
        make.right.equalTo(self.view.mas_right).with.offset(-5);
    }];
        _m_collerction.dataSource = self;
        _m_collerction.delegate = self;
    [_m_collerction registerClass:[SkinCell class] forCellWithReuseIdentifier:@"skinCell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _m_dataSource.count;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SkinCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"skinCell" forIndexPath:indexPath];
    cell.m_image = _m_dataSource[indexPath.item];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  
    [[MotiveManager shareMotiveManager] changeBackImageWithName:[NSString stringWithFormat:@"%ld", indexPath.item + 1] AndType:@"jpg"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
